var assert = require('assert');
var should = require('should');
var util = require('util');
var _ = require('lodash');
var copyRecordModel = require('../../app/models/copyRecordModel');
var config = require('../config');
var atkData = require('../../app/libs/war/atkData');
var copyData = require('../../app/libs/war/copyData');

suite('测试CopyRecordModel', function () {
    var copy_record_model;
    suite('添加一个战斗记录', function () {
        test('添加战斗记录成功', function (done) {
            atkData.getData(config.role_id, function (err, atk_data) {
                var def_data = copyData.getData(10101);
                assert.equal(!!def_data, true);
                copyRecordModel.addRecord(config.role_id, 1, 10101, atk_data, def_data, function (err, model) {
                    copy_record_model = model;

                    // 验证所有的比例加起来是100
                    var total_per = 0;
                    _.each(copy_record_model.def.build_list, function (build_item) {
                        total_per += build_item.per;
                    });
                    Math.ceil(total_per).should.equal(100);

                    copy_record_model.getCup();
                    copy_record_model.getDefName();
                    copy_record_model.getDefBuildList();
                    copy_record_model.getDefTotalGold();
                    copy_record_model.getDefTotalExp();
                    copy_record_model.getStar();
                    copy_record_model.setStar(1);
                    copy_record_model.getProgress(1);
                    copy_record_model.toJSON();
                    done();
                });
            });
        });
    });

    suite('获取一个战斗记录', function () {
        test('获取战斗记录成功', function (done) {
            copyRecordModel.getRecordByAtkRoleId(config.role_id,
                copy_record_model.getRecordId(),
                function (err, model) {
                    copy_record_model = model;
                    done();
                });
        });
    });
});
